﻿using System;
using System.Web;
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework.Config;
using Castle.Core.Resource;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using MyFirstCastle.Web.Models;


namespace MyFirstCastle.Web
{
    public class Global : HttpApplication, IContainerAccessor
    {
        private static IWindsorContainer container;

        protected void Application_Start(object sender, EventArgs e)
        {
            container = new WindsorContainer(new XmlInterpreter(new ConfigResource()));

            //ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance,
            //        new Type[] { typeof(Supplier), typeof(Product) });

            ////if you want to let AR to create the schema for you
            //ActiveRecordStarter.CreateSchema();
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            container.Dispose();
        }

        public IWindsorContainer Container
        {
            get { return container; }
        }
    }
}